package eSchool.GUI.Components;

import eSchool.Utils.CSVFilter;
import eSchool.Utils.Import;
import java.awt.CardLayout;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;

public class Desktop extends javax.swing.JFrame {

    public Desktop() {
        initComponents();
        this.setSize(700, 550);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panDesktop1 = new eSchool.GUI.Components.panDesktop();
        menuBar = new javax.swing.JMenuBar();
        mnFicheiro = new javax.swing.JMenu();
        jSeparator1 = new javax.swing.JSeparator();
        mnISair = new javax.swing.JMenuItem();
        mnAlunos = new javax.swing.JMenu();
        mnIAlunoNovo = new javax.swing.JMenuItem();
        mnIAlunoCons = new javax.swing.JMenuItem();
        mnDisciplinas = new javax.swing.JMenu();
        mnIDiscipInserir = new javax.swing.JMenuItem();
        mnIDiscipCons = new javax.swing.JMenuItem();
        mnDocentes = new javax.swing.JMenu();
        mnIDocInserir = new javax.swing.JMenuItem();
        mnIDocCons = new javax.swing.JMenuItem();
        mnFuncionarios = new javax.swing.JMenu();
        mnIFuncInserir = new javax.swing.JMenuItem();
        mnIFuncCons = new javax.swing.JMenuItem();
        mnNotas = new javax.swing.JMenu();
        mnIImportar = new javax.swing.JMenuItem();
        mnIExportar = new javax.swing.JMenuItem();
        mnUtilizadores = new javax.swing.JMenu();
        mnIUtiliInserir = new javax.swing.JMenuItem();
        mnIUtiliCons = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("E-School"); // NOI18N
        setResizable(false);
        getContentPane().setLayout(new java.awt.CardLayout());
        getContentPane().add(panDesktop1, "card2");

        menuBar.setDoubleBuffered(true);

        mnFicheiro.setText("Ficheiro"); // NOI18N
        mnFicheiro.add(jSeparator1);

        mnISair.setText("Sair"); // NOI18N
        mnISair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnISairActionPerformed(evt);
            }
        });
        mnFicheiro.add(mnISair);

        menuBar.add(mnFicheiro);

        mnAlunos.setText("Alunos"); // NOI18N
        mnAlunos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnAlunosActionPerformed(evt);
            }
        });

        mnIAlunoNovo.setText("Inserir"); // NOI18N
        mnIAlunoNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnIAlunoNovoActionPerformed(evt);
            }
        });
        mnIAlunoNovo.addMenuKeyListener(new javax.swing.event.MenuKeyListener() {
            public void menuKeyPressed(javax.swing.event.MenuKeyEvent evt) {
                mnIAlunoNovoMenuKeyPressed(evt);
            }
            public void menuKeyReleased(javax.swing.event.MenuKeyEvent evt) {
            }
            public void menuKeyTyped(javax.swing.event.MenuKeyEvent evt) {
            }
        });
        mnAlunos.add(mnIAlunoNovo);

        mnIAlunoCons.setText("Consultar"); // NOI18N
        mnIAlunoCons.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnIAlunoConsActionPerformed(evt);
            }
        });
        mnAlunos.add(mnIAlunoCons);

        menuBar.add(mnAlunos);

        mnDisciplinas.setText("Disciplinas"); // NOI18N

        mnIDiscipInserir.setText("Inserir"); // NOI18N
        mnIDiscipInserir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnIDiscipInserirActionPerformed(evt);
            }
        });
        mnDisciplinas.add(mnIDiscipInserir);

        mnIDiscipCons.setText("Consultar"); // NOI18N
        mnIDiscipCons.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnIDiscipConsActionPerformed(evt);
            }
        });
        mnDisciplinas.add(mnIDiscipCons);

        menuBar.add(mnDisciplinas);

        mnDocentes.setText("Docentes"); // NOI18N

        mnIDocInserir.setText("Inserir"); // NOI18N
        mnIDocInserir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnIDocInserirActionPerformed(evt);
            }
        });
        mnDocentes.add(mnIDocInserir);

        mnIDocCons.setText("Consultar"); // NOI18N
        mnIDocCons.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnIDocConsActionPerformed(evt);
            }
        });
        mnDocentes.add(mnIDocCons);

        menuBar.add(mnDocentes);

        mnFuncionarios.setText("Funcionarios");

        mnIFuncInserir.setText("Inserir");
        mnIFuncInserir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnIFuncInserirActionPerformed(evt);
            }
        });
        mnFuncionarios.add(mnIFuncInserir);

        mnIFuncCons.setText("Consultar");
        mnIFuncCons.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnIFuncConsActionPerformed(evt);
            }
        });
        mnFuncionarios.add(mnIFuncCons);

        menuBar.add(mnFuncionarios);

        mnNotas.setText("Notas"); // NOI18N

        mnIImportar.setText("Importar CSV"); // NOI18N
        mnIImportar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnIImportarActionPerformed(evt);
            }
        });
        mnNotas.add(mnIImportar);

        mnIExportar.setText("Exportar CSV"); // NOI18N
        mnNotas.add(mnIExportar);

        menuBar.add(mnNotas);

        mnUtilizadores.setText("Utilizadores");

        mnIUtiliInserir.setText("Inserir");
        mnIUtiliInserir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnIUtiliInserirActionPerformed(evt);
            }
        });
        mnUtilizadores.add(mnIUtiliInserir);

        mnIUtiliCons.setText("Consultar");
        mnIUtiliCons.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnIUtiliConsActionPerformed(evt);
            }
        });
        mnUtilizadores.add(mnIUtiliCons);

        menuBar.add(mnUtilizadores);

        setJMenuBar(menuBar);

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void mnIAlunoNovoMenuKeyPressed(javax.swing.event.MenuKeyEvent evt) {//GEN-FIRST:event_mnIAlunoNovoMenuKeyPressed
    }//GEN-LAST:event_mnIAlunoNovoMenuKeyPressed

    private void mnIAlunoConsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnIAlunoConsActionPerformed
        CardLayout cl = (CardLayout) (panDesktop1.getLayout());
        cl.show(panDesktop1, "cardAlunos");
        panDesktop1.setModo(UIMode.LISTA, "ListaAlunos");

    }//GEN-LAST:event_mnIAlunoConsActionPerformed

    private void mnIDocConsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnIDocConsActionPerformed
        CardLayout cl = (CardLayout) (panDesktop1.getLayout());
        cl.show(panDesktop1, "cardDocentes");
        panDesktop1.setModo(UIMode.LISTA, "ListaDocentes");
    }//GEN-LAST:event_mnIDocConsActionPerformed

    private void mnISairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnISairActionPerformed
        System.exit(0);
    }//GEN-LAST:event_mnISairActionPerformed

    private void mnAlunosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnAlunosActionPerformed
    }//GEN-LAST:event_mnAlunosActionPerformed

    private void mnIAlunoNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnIAlunoNovoActionPerformed

        CardLayout cl = (CardLayout) (panDesktop1.getLayout());
        cl.show(panDesktop1, "cardAlunos");
        panDesktop1.setModo(UIMode.DETALHE, "NovoAluno");

    }//GEN-LAST:event_mnIAlunoNovoActionPerformed

    private void mnIDiscipInserirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnIDiscipInserirActionPerformed
       CardLayout cl = (CardLayout) (panDesktop1.getLayout());//GEN-LAST:event_mnIDiscipInserirActionPerformed
        cl.show(panDesktop1, "cardDisciplinas");
        panDesktop1.setModo(UIMode.DETALHE, "NovaDisciplina");
    }

    private void mnIDiscipConsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnIDiscipConsActionPerformed
        CardLayout cl = (CardLayout) (panDesktop1.getLayout());
        cl.show(panDesktop1, "cardDisciplinas");
        panDesktop1.setModo(UIMode.LISTA, "ListaDisciplinas");
    }//GEN-LAST:event_mnIDiscipConsActionPerformed

    private void mnIDocInserirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnIDocInserirActionPerformed
        CardLayout cl = (CardLayout) (panDesktop1.getLayout());
        cl.show(panDesktop1, "cardDocentes");
        panDesktop1.setModo(UIMode.DETALHE, "NovoDocente");

    }//GEN-LAST:event_mnIDocInserirActionPerformed

    private void mnIFuncConsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnIFuncConsActionPerformed
        CardLayout cl = (CardLayout) (panDesktop1.getLayout());
        cl.show(panDesktop1, "cardFuncionarios");
        panDesktop1.setModo(UIMode.LISTA, "ListaFuncionarios");
}//GEN-LAST:event_mnIFuncConsActionPerformed

    private void mnIFuncInserirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnIFuncInserirActionPerformed
        CardLayout cl = (CardLayout) (panDesktop1.getLayout());
        cl.show(panDesktop1, "cardFuncionarios");
        panDesktop1.setModo(UIMode.DETALHE, "NovoFuncionario");

}//GEN-LAST:event_mnIFuncInserirActionPerformed

    private void mnIImportarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnIImportarActionPerformed
        try {
            BufferedReader bIn;

            JFileChooser fcImport = new JFileChooser();
            fcImport.resetChoosableFileFilters();

            fcImport.removeChoosableFileFilter(fcImport.getFileFilter());
            fcImport.setFileFilter(new CSVFilter());
            fcImport.setDialogTitle("Importar ficheiro CSV");

            int ret = fcImport.showDialog(this, "Ok");

            if (ret != fcImport.APPROVE_OPTION) {
                return;
            }

            Import imported = new Import();

            imported.load(fcImport.getSelectedFile().getAbsolutePath());

        } catch (IOException ex) {
            Logger.getLogger(Desktop.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(Desktop.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_mnIImportarActionPerformed

private void mnIUtiliInserirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnIUtiliInserirActionPerformed
// TODO add your handling code here:
    CardLayout cl = (CardLayout) (panDesktop1.getLayout());
    cl.show(panDesktop1, "cardUtilizadores");
    panDesktop1.setModo(UIMode.DETALHE, "NovoUtilizador");

}//GEN-LAST:event_mnIUtiliInserirActionPerformed

private void mnIUtiliConsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnIUtiliConsActionPerformed
// TODO add your handling code here:
    CardLayout cl = (CardLayout) (panDesktop1.getLayout());
    cl.show(panDesktop1, "cardUtilizadores");
    panDesktop1.setModo(UIMode.LISTA, "ListaUtilizador");
}//GEN-LAST:event_mnIUtiliConsActionPerformed
//    private void applicationExitActionPerformed(WindowEvent e){
//        exit(true);
//    }
//    private void exit(boolean confirm) {
//        int i = JOptionPane.YES_OPTION;
//
//        if (confirm) {
//            i = JOptionPane.showConfirmDialog(null, "Deseja fechar a aplicação?", "Saída", JOptionPane.YES_NO_OPTION);
//        }
//
//        if (i == JOptionPane.YES_OPTION) {
//            System.exit(0);
//        }
//
//    }

//    private void applicationExitActionPerformed(WindowEvent e){
//        exit(true);
//    }
//    
//    private void exit(boolean confirm){
//        int i= JOptionPane.YES_OPTION;
//        
//        if(confirm)
//            i = JOptionPane.showConfirmDialog(null , "Deseja fechar a aplicação?", "Saída", JOptionPane.YES_NO_OPTION);
//        
//        if (i == JOptionPane.YES_OPTION) {
//            
//            System.exit(0);
//        }
//        
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenu mnAlunos;
    private javax.swing.JMenu mnDisciplinas;
    private javax.swing.JMenu mnDocentes;
    private javax.swing.JMenu mnFicheiro;
    private javax.swing.JMenu mnFuncionarios;
    private javax.swing.JMenuItem mnIAlunoCons;
    private javax.swing.JMenuItem mnIAlunoNovo;
    private javax.swing.JMenuItem mnIDiscipCons;
    private javax.swing.JMenuItem mnIDiscipInserir;
    private javax.swing.JMenuItem mnIDocCons;
    private javax.swing.JMenuItem mnIDocInserir;
    private javax.swing.JMenuItem mnIExportar;
    private javax.swing.JMenuItem mnIFuncCons;
    private javax.swing.JMenuItem mnIFuncInserir;
    private javax.swing.JMenuItem mnIImportar;
    private javax.swing.JMenuItem mnISair;
    private javax.swing.JMenuItem mnIUtiliCons;
    private javax.swing.JMenuItem mnIUtiliInserir;
    private javax.swing.JMenu mnNotas;
    private javax.swing.JMenu mnUtilizadores;
    private eSchool.GUI.Components.panDesktop panDesktop1;
    // End of variables declaration//GEN-END:variables
}
